package com.szqhyxj.youxiangju.sys.components.androidpicker.qqtheme.framework.util;

import android.app.Activity;
import android.util.Log;

import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.sys.components.androidpicker.AddressPickTask;
import com.szqhyxj.youxiangju.sys.components.androidpicker.qqtheme.framework.picker.DatePicker;
import com.szqhyxj.youxiangju.sys.components.androidpicker.qqtheme.framework.picker.OptionPicker;
import com.szqhyxj.youxiangju.sys.components.androidpicker.qqtheme.framework.widget.WheelView;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * XiaoPanYu
 * on 2018/10/26
 */
public class PickerUtil {

    /**
     * 年月
     *
     * @param activity
     * @param listener
     */
    public static void onMonthDayPicker(Activity activity, DatePicker.OnYearMonthDayPickListener listener) {
        DatePicker picker = new DatePicker(activity, DatePicker.YEAR_MONTH_DAY);
        picker.setUseWeight(false);
        picker.setTextPadding(ConvertUtils.toPx(activity, 15));//加宽显示项
        picker.setDividerRatio(WheelView.DividerConfig.FILL);//弹框居中
        Map<String, Integer> map = getData();
          picker.setSelectedItem(map.get("year"),map.get("month"), map.get("day"));

       /* picker.setRangeStart(5, 1);
        picker.setRangeEnd(12, 31);
        picker.setSelectedItem(10, 14);*/
        picker.setOnDatePickListener(listener);
        picker.show();
    }

    public static Map<String, Integer> getData() {
        Map<String, Integer> map = new HashMap<>();

        Calendar calendar = Calendar.getInstance(); //获取系统的日期 //年
         int year = calendar.get(Calendar.YEAR); //月
         int month = calendar.get(Calendar.MONTH)+1; //日
         int day = calendar.get(Calendar.DAY_OF_MONTH);

        map.put("year", year);
        map.put("month", month);
        map.put("day", day);
        return map;
    }

    /**
     * 单向选择器
     *
     * @param activity
     * @param listener
     */
    public static void onOptionPicker(Activity activity, String[] strings, OptionPicker.OnOptionPickListener listener) {
        OptionPicker picker = new OptionPicker(activity, strings);
        picker.setCanceledOnTouchOutside(false);
        picker.setDividerRatio(WheelView.DividerConfig.FILL);
        picker.setShadowColor(activity.getResources().getColor(R.color.invitationColor), 40);
        picker.setSelectedIndex(1);
        picker.setCycleDisable(true);
        picker.setTextSize(12);
        picker.setTextColor(activity.getResources().getColor(R.color.colorTextBlack));
        picker.setTextPadding(ConvertUtils.toPx(activity, 10));//加宽显示项
        picker.setLineSpaceMultiplier(2.5f);
        picker.setOnOptionPickListener(listener);
        picker.show();
    }

    /**
     * 单向选择器
     *
     * @param activity
     * @param listener
     */
    public static void onOptionPicker(Activity activity, String[] strings, String title, OptionPicker.OnOptionPickListener listener) {
        OptionPicker picker = new OptionPicker(activity, strings);
        picker.setCanceledOnTouchOutside(false);
        picker.setTitleText(title);
        picker.setDividerRatio(WheelView.DividerConfig.FILL);
        picker.setShadowColor(activity.getResources().getColor(R.color.invitationColor), 40);
        picker.setSelectedIndex(1);
        picker.setCycleDisable(true);
        picker.setTextSize(12);
        picker.setTextColor(activity.getResources().getColor(R.color.colorTextBlack));
        picker.setTextPadding(ConvertUtils.toPx(activity, 10));//加宽显示项
        picker.setLineSpaceMultiplier(2.5f);
        picker.setOnOptionPickListener(listener);
        picker.show();
    }

    public static void onDayPicker(Activity activity, OptionPicker.OnOptionPickListener listener) {

        OptionPicker picker = new OptionPicker(activity, getDatas());
        picker.setCanceledOnTouchOutside(false);
        picker.setDividerRatio(WheelView.DividerConfig.FILL);
        picker.setShadowColor(activity.getResources().getColor(R.color.invitationColor), 40);
        picker.setSelectedIndex(1);
        picker.setCycleDisable(true);
        picker.setTextSize(12);
        picker.setTextColor(activity.getResources().getColor(R.color.colorTextBlack));
        picker.setTextPadding(ConvertUtils.toPx(activity, 10));//加宽显示项
        picker.setLineSpaceMultiplier(2.5f);
        picker.setOnOptionPickListener(listener);
        picker.show();
    }


    public static String[] getDatas() {
        String[] datas = new String[31];
        for (int i = 1; i <= 31; i++) {
            datas[i - 1] = i + "日";
        }

        return datas;
    }


    /**
     * 地区选择器
     *
     * @param
     * @param
     */
    public static void onAddressPicker(Activity context, String json, AddressPickTask.Callback callback) {
        AddressPickTask task = new AddressPickTask(context);
        task.setHideProvince(false);
        task.setHideCounty(false);
        task.setCallback(callback);
        task.setJson(json);
        task.execute();
    }


}
